var app=getApp();
Page({
  onLoad(e){
//    console.log(e.order_id)
    this.setData({ order_id: e.order_id});
    this.detail();
  },
  detail() {
    let token = wx.getStorageSync('token');
    let user_id = wx.getStorageSync('userdata').user_id;
    let order_id = this.data.order_id;
    let json = { token: token, user_id: user_id, order_id: order_id }
//    console.log(json)
    app.request('book/order/orderDetail', 'GET', json, 'detailb', this);
  },
  detailb(data) {
//    console.log(data);
    data.data.books.forEach((item2, index) => {//图片地址
      item2.img_medium = item2.img_medium.split('@')[0];
    })
    this.setData({ lists: data.data.books})
  },
  buyone(e){
    let book_id=e.currentTarget.id;
    let token=wx.getStorageSync('token');
    let user_id = wx.getStorageSync('userdata').user_id;
    let order_id=this.data.order_id;
    let openId=wx.getStorageSync('openid');
    let json = { book_id: book_id,token:token,user_id:user_id,order_id:order_id,
      pay_method: 6, openId: openId}
    app.request('book/purchase/index','POST',json,'buoneb',this)
  },
  buoneb(data){
    if (data.code&&data.code!=200){
      app.tishi('提示',data.msg);
      return false
    }
    let _this=this;
    wx.requestPayment({
      'timeStamp': data.timeStamp,
      'nonceStr': data.nonceStr,
      'package': data.package,
      'signType': data.signType,
      'paySign': data.paySign,
      success(e) {
        wx.hideLoading();
        wx.showToast({ title: '购买成功！', icon: 'success', mask: true, duration: 1000 });
        _this.detail();
      },
      fail(e) {
        wx.hideLoading();
        wx.showToast({ title: '支付取消', mask: true, icon: 'none', duration: 500 });
      }
    })
  },
})